import 'package:flutter/material.dart';
import 'package:imove/extension/icons_ext.dart';
import 'package:imove/utils/screen_util.dart';
import '../confit.dart';

class HomeAppBar extends StatelessWidget implements PreferredSizeWidget{
  final double contentHeight;
  const HomeAppBar({Key key, this.contentHeight = 60}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: ScreenUtils.getStatusBarH(),left: 10,right: 10,bottom: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.0),
        boxShadow: [
          BoxShadow(
            color: Colors.grey.withOpacity(.4),//Color.fromRGBO(93, 223, 212, 0.4),
            offset: Offset(0.0, 0.0), //阴影xy轴偏移量
            blurRadius: 2.0, //阴影模糊程度
            // spreadRadius: 1.0 //阴影扩散程度
          )
        ]
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              _logoText(),
              _rightAction()
            ],
          ),
          SizedBox(height: 10,),
          _bottomSearch()
        ],
      ),
    );
  }

  Widget _logoText(){
    Gradient textGradient = LinearGradient(
      begin: Alignment.centerLeft,
      end: Alignment.centerRight,
      colors: [Colors.red, Colors.blue]
    );
    Shader textShader = textGradient.createShader(Rect.fromLTRB(0, 0, 120, 40));
    return Text(
      '帅帅影视',
      style: TextStyle(
        foreground: Paint()..shader=textShader,
        fontSize: 30,
        fontWeight: FontWeight.bold
      )
    );
  }

  Widget _rightAction(){
    return Row(
      children: [
        GestureDetector(
          child: Padding(
            padding: EdgeInsets.all(5),
            child: Icon(Icons.history,size: 28,),
          ),
        ),
        GestureDetector(
          child: Padding(
            padding: EdgeInsets.all(5),
            child: Icon(MyIcon.my_rank,size: 28,),
          ),
        ),
      ],
    );
  }

  Widget _bottomSearch(){
    return GestureDetector(
      child: Container(
        height: 40,
        padding: EdgeInsets.all(5),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(20)),
          color: AppColor.search_bg_grey,
        ),
        child: Row(
          children: [
            Icon(Icons.search,size: 16,),
            Text(
              "海量影片精彩看不停",
              style: TextStyle(
                fontSize: 14,
              ),
            )
          ],
        ),
      ),
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(contentHeight + ScreenUtils.getStatusBarH());
}